/*
 * $Id: DbAppView.java 57 2009-05-13 05:04:03Z donbeave $
 */

package labour.dbmanager.client.mvc;

import labour.dbmanager.client.connector.json.JsonNavigationConnector;
import labour.dbmanager.client.widget.NavigationContextMenu;
import labour.manager.client.AppEvents;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.binder.TreeBinder;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Controller;
import com.extjs.gxt.ui.client.mvc.View;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.tree.Tree;

public class DbAppView extends View {

  public DbAppView(Controller controller) {
    super(controller);
  }

  @Override
  protected void handleEvent(AppEvent event) {
    if (event.getType() == AppEvents.Prepare) {
      onPrepare();
    }
  }

  protected void onPrepare() {
    ContentPanel east = (ContentPanel) Registry.get(labour.manager.client.mvc.AppView.EAST_PANEL);

    JsonNavigationConnector connector = new JsonNavigationConnector("/instances/sqlmanager/");

    ContentPanel panel = new ContentPanel();
    panel.setHeading("Db Manager");
    panel.setScrollMode(Scroll.AUTO);


    Tree tree = new Tree();

    new NavigationContextMenu(tree);

    TreeBinder binder = new TreeBinder(tree, connector.getStore());
    binder.setDisplayProperty("name");


    panel.add(tree);


    east.add(panel);

    connector.getStore().getLoader().load();

  }

}
